﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using JumJob.Models;
namespace JumJob.Models
{
    public partial class Category
    {
        jum_jobEntities jjDB;
        public Category() 
        {
            jjDB =new jum_jobEntities();
           
        }


        public List<Job> getJobList(int max=0) 
        {

            List<Job> trabajos = null ;
            if(max!=0)
              trabajos = (from job in jjDB.jum_job
                                where job.category_id==this.id
                                orderby job.started_at descending
                                select job).Take(max).ToList<Job>();
            else
                trabajos = (from job in jjDB.jum_job
                            where job.category_id == this.id
                            orderby job.started_at descending
                            select job).ToList<Job>();
        
            return trabajos;
        }

       



        public int getJobCount() 
        {
            return (from job in jjDB.jum_job
                    where job.category_id == this.id
                    select job).Count();
        }

      

        public static List<Category> getCategoryList() 
        {
            using (jum_jobEntities jjDB = new jum_jobEntities()) 
            {
                return (from category in jjDB.jum_category
                       select category).ToList();
            }
        }
    }
}